package com.atguigu.gulimall.gulimallgateway.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;
import org.springframework.web.cors.reactive.CorsWebFilter;


@Configuration
public class CorsConfig {

    @Bean
    public CorsWebFilter corsWebFilter() {
        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();

        CorsConfiguration configuration = new CorsConfiguration();
        configuration.addAllowedHeader("*");    //允许任何来源跨域
        configuration.addAllowedMethod("*");    //允许任何方法跨域
        configuration.addAllowedOrigin("*");    //允许所有请求来源跨域，暂且如此
        configuration.setAllowCredentials(true);//允许携带cookie跨域

        source.registerCorsConfiguration("/**", configuration);
        return new CorsWebFilter(source);
    }

}
